﻿@using CubicFWNet.Data.Models
@model List<GradeMaintenance>
@{
    //ViewBag.Title = "价格核算";
}
<section class="content-header">
    <h1>
        加工类别维护
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("GradeMaintenanceService", "FinanceCost")">加工类别维护</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                <form class="form-horizontal" id="frmedit" action="@Url.Action("AddOrUpdateGradeMaintenance", "FinanceCost")" method="post">
                    <div class="box-body">
                        <div id="all-content">
                            @if (Model != null && Model.Count == 0)
                            {
                                <input type="hidden" id="sign" name="sign" value="-1" />
                                for (int i = 1; i < 6; i++)
                                {
                                    <div class="json-content">
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">@i 类</label>
                                            <div class="col-sm-9">
                                                <input type="hidden" id="GmId" name="GmId" value="@i" />
                                                <input type="hidden" id="GmName" name="GmName" value="@i 类" />
                                                <input type="hidden" id="Type" name="Type" value="2" />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">加工人工-元/分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="Money" name="Money" value="" data-des="加工人工-元/分钟" />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                    </div>
                                }
                            }
                            @if (Model != null && Model.Count != 0)
                            {
                                <input type="hidden" id="sign" name="sign" value="1" />
                                for (int i = 1; i < 6; i++)
                                {
                                    <div class="json-content">
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">@i 类</label>
                                            <div class="col-sm-9">
                                                <input type="hidden" id="GmId" name="GmId" value="@i" />
                                                <input type="hidden" id="GmName" name="GmName" value="@i 类" />
                                                <input type="hidden" id="Id" name="Id" value="@Model[i - 1].Id" />
                                                <input type="hidden" id="Type" name="Type" value="2" />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                        <div class="form-group col-md-6">
                                            <label class="col-sm-3 control-label">加工人工-元/分钟</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control okeydown" id="Money" name="Money" value="@Model[i - 1].Money" data-des="加工人工-元/分钟" />
                                            </div>
                                        </div>
                                        <div class="form-group col-md-12" style="height: 1px;"></div>
                                    </div>
                                }
                            }
                        </div>
                    </div>
                    <div class="box-footer" style="width: 80%; margin-left: 20px;">
                        <a role="button" href="javascript:void(0)" class="btn btn-primary submitbtn" onclick="formsubmit(1)">保存</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>
<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

<style>
    .has-error {
        border-color: #dd4b39;
        box-shadow: none;
    }
</style>


@section Scripts{
    <script type="text/javascript">
            $(document).ready(function () {
                $("#frmedit").validate({
                    submitHandler: function (form) {
                        var postData = $(form).formSerialize();
                        postData.Data = getParam();
                        //postData.EquipmentId = $("#EquipmentId").val();
                        //postData.sign = $("#sign").val();
                        $.submitForm({
                            url: $(form).attr("action"),
                            param: postData,
                            success: function () {
                                $.modalAlert("操作成功", "success");
                                window.location.href = '@Url.Action("GradeMaintenanceTwo", "FinanceCost")';
                            }
                        });
                    }
                });

                //var yy = document.getElementById("modalData").value;
                //alert(yy.length);

            });

            function formsubmit(t) {
                $("#frmedit").submit();
            }

            $(".okeydown").on("keyup", function () {
                var value = $(this).val();
                if (isNaN(value) || value == "" || value == "Infinity" || value == "NaN") {
                    $(this).addClass("has-error");
                } else {
                    $(this).removeClass("has-error");
                }
            });


            $(".okeydown").on("keydown", function () {
                var k = event.keyCode;
                if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                    return true;
                } else {
                    return false;
                }
            });

            function getParam() {
                var postdata = [];
                $("#all-content").find('.json-content').each(function (r, i) {
                    var postdataItem = {};
                    $(i).find('input').each(function (m) {
                        var $this = $(this);
                        var id = $this.attr('id');
                        var value = $this.val();
                        if (value == "") {
                            value = "0";
                        }
                        postdataItem[id] = value;
                    });
                    postdata.push(postdataItem);
                });
                //return postdata;
                return JSON.stringify(postdata);
            }
    </script>
}






